<div id="homepage">
  <div class="container clearfix">

      <div class="homepage_content clearfix">
        <%= raw(@settings.homepage_content) %>
      </div>

    <div class="campaigns">

      <% if @campaigns.count > 0 %>
        <% @campaigns.each do |campaign| %>
          <% if campaign.published_flag %>
          <a href="<%= url_for campaign_home_path(campaign) %>" class="campaign clearfix">

            <% if campaign.media_type == 'video' && !campaign.video_embed_id.blank?%>

              <% if campaign.video_placeholder.file? %>
                <%= image_tag campaign.video_placeholder.url(:main), alt: "main_image" %>
              <% else %>
                <%= image_tag "https://img.youtube.com/vi/#{campaign.video_embed_id}/hqdefault.jpg", alt: "main_image" %>
              <% end %>

            <% else %>

              <% if campaign.main_image.file? %>
                <%= image_tag campaign.main_image.url(:small), alt: "main_image" %>
              <% else %>
                <div class="placeholder"></div>
              <% end %>

            <% end %>

            <p class="info">
              <%= truncate(campaign.name, length: 50) %>
            </p>

            <% if campaign.raised_amount.to_f/100 < campaign.goal_dollars.to_f %>
              <div id='progress_bg'>
                <div id='progress' class='' style='width: <%= campaign.tilt_percent.nil? ? 0 : campaign.tilt_percent.ceil %>%;'>
                </div>
              </div>
            <% else %>
              <div id="progress_bg">
                <div id="progress">
                </div>
                </div>
            <% end %>

            <p class="numbers pull-left">
              <% if campaign.goal_type == 'dollars' %>
              <strong>$<%= campaign.raised_amount.ceil %></strong><br/>
              <%= campaign.progress_text %>
              <% else %>
               <strong><%= campaign.orders %></strong><br/>
              <%= campaign.contributor_reference.pluralize(campaign.orders) %>
              <% end %>
            </p>

            <p class="numbers pull-right" style="text-align:right">
            <% if campaign.expired? %>
              <strong>No</strong><br/>days left!
            <% else %>
              <strong><%= distance_of_time_in_words_to_now(campaign.expiration_date).gsub(/\D/, "") %></strong>
              <span style="display: block; width: 100px;">
                <%= distance_of_time_in_words_to_now(campaign.expiration_date).gsub(/\d/, "").gsub("about", "") %> left
              </span>
            <% end %>
            </p>

          </a>
          <% end %>
        <% end %>
      <% else %>

      <div class="center" style="padding-left:0px"><h4>No campaigns yet. <% if user_signed_in? && current_user.admin? %><%= link_to 'Start one now!', new_admin_campaign_path %><% end %></h4></div>

      <% end %>
    </div>
  </div>
</div>